package com.mes.cloud.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.mes.cloud.dao.BmeBcDAO;
import com.mes.cloud.dao.BmeBcDigitalDAO;
import com.mes.cloud.dto.BmeBcDTO;
import com.mes.cloud.dto.BmeBcDigitalDTO;
import com.mes.cloud.service.BmeBcDigitalService;
import com.mes.cloud.util.CommPager;
import com.mes.cloud.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* 数字化配置
* @author wxm
* @Time 2020-4-9
*/
@Service
public class BmeBcDigitalServiceImpl implements BmeBcDigitalService {
    @Autowired
    private BmeBcDigitalDAO bmeBcDigitalDAO;

    @Autowired
    private BmeBcDAO bmeBcDAO;

    @Override
    public List<BmeBcDigitalDTO> findList(Map<Object, Object> condition) {
        return bmeBcDigitalDAO.findList(condition);
    }

    @Override
    public long getCount(Map<Object, Object> condition) {
        return bmeBcDigitalDAO.getCount(condition);
    }

    @Override
    public long insert(BmeBcDigitalDTO bmeBcDigitalDTO) {
        return bmeBcDigitalDAO.insert(bmeBcDigitalDTO);
    }

    @Override
    public long update(BmeBcDigitalDTO bmeBcDigitalDTO) {
        return bmeBcDigitalDAO.update(bmeBcDigitalDTO);
    }

    @Override
    public long delete(Integer id) {
        return bmeBcDigitalDAO.delete(id);
    }

    @Override
    public BmeBcDigitalDTO get(Integer id) {
        return bmeBcDigitalDAO.get(id);
    }

    @Override
    public long enable(Map<Object, Object> map) throws Exception {
        if (map.get("id") == null || map.get("isEnable") == null) {
            throw new Exception("参数异常");
        }
        return bmeBcDigitalDAO.enable(map);
    }

    @Override
    public Object findListByBcCode(Map<Object, Object> map) {
        BmeBcDTO bmeBcDTO = bmeBcDAO.getBmeBcByCode(map.get("code").toString());
        Map selectParam = new HashMap();
        selectParam.put("bcId",bmeBcDTO.getId());
        if(map.containsKey("chartType")){
            selectParam.put("chartType",map.get("chartType").toString());
        }
        return bmeBcDigitalDAO.findList(selectParam);
    }


    @Override
    public CommPager<BmeBcDigitalDTO> findPageList(Map<Object, Object> condition) {
        int pageIndex = condition.get("pageIndex") == null ? 0 : Integer.valueOf(condition.get("pageIndex").toString());
        int pageSize = condition.get("pageSize") == null ? 10 : Integer.valueOf(condition.get("pageSize").toString());
        Page<BmeBcDigitalDTO> page = PageHelper.startPage(pageIndex, pageSize, true);
        List<BmeBcDigitalDTO> dictList = bmeBcDigitalDAO.findList(condition);
        CommPager<BmeBcDigitalDTO> pageResult = new CommPager<>(page, dictList);
        return pageResult;
    }
}
